package com.yiwan.dao;


import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;



import com.yiwan.entity.User;

import tool.JDBConnection;


public class UserDao {
	private static Logger log = Logger.getLogger(UserDao.class);
	private JDBConnection connection = null;
	private String sql = null;
	public String isLogin(User uf) throws Exception {
		String info = "";
		try {
			connection = new JDBConnection();
			//boolean flag = false;
			sql = "select userid,uname,password,email,qq,telephone,weixin,location from user where uname = '"+uf.getUname()+"' and password = "+uf.getPassword();
			ResultSet rs = connection.executeQuery(sql);
			if (rs.next()) {
				info = rs.getString(1)+","+rs.getString(2)+","+rs.getString(3)+","+rs.getString(4)+","+rs.getString(5)+","+rs.getString(6)+","+rs.getString(7)+","+rs.getString(8);
				return info;
			}
			
		
		} catch (Exception e) {
			log.debug(""+e);
		} finally {
			connection.closeConnection();
		}
		return "";
		
	}
	public boolean isSign(User uf) {
		try {
			connection = new JDBConnection();
			boolean flag = false;
			log.info("insert");
			sql = "insert into userinfo(uname,password,email,qq,telephone,weixin,location) values('"+uf.getUname()+"','"+uf.getPassword()+"','"+uf.getEmail()+"','"+uf.getQq()+"','"+uf.getTelephone()+"','"+uf.getWeixin()+"','"+uf.getLocation()+"')";
			
			if (connection.executeUpdate(sql)) {
				flag = true;
			}
			return flag;
		
		} catch (Exception e) {
			log.debug(""+e);
		} finally {
			connection.closeConnection();
		}
		return false;
		
	}
	public boolean isExit(User uf) {
		try {
			connection = new JDBConnection();
			boolean flag = false;
			sql = "select * from userinfo where email = '"+uf.getEmail()+"'";
			ResultSet rs = connection.executeQuery(sql);
			if (rs.next()) {
				flag = true;
			}
			return flag;
		
		} catch (Exception e) {
			log.debug(""+e);
		} finally {
			connection.closeConnection();
		}
		return false;
		
	}

}




